<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var countBadPairs = function (nums) {
    const n = nums.length
    let ans = n * (n - 1) / 2;
    const m = new Map();
    for (let i = 0; i < n; i++) {
        const d = nums[i] - i;
        let v = m.has(d) ? m.get(d) : 0;
        m.set(d, v + 1);
    }
    for (let [k, v] of m) {
        ans -= v * (v - 1) / 2;
    }
    return ans;
};
</script>
</html>